<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch">
            <el-form-item label="名称" prop="dictType">
                <el-input v-model="queryParams.name" placeholder="请输入任务名称" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <el-select v-model="queryParams.state" placeholder="请选择">
                    <el-option v-for="item in stateList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8" ref="refbut">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" v-hasPermi="['archive:mgck:add']" @click="handleAdd">添加</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" v-hasPermi="['archive:mgck:delete']" @click="handleDeleteAll">删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-upload2" v-hasPermi="['archive:mgck:import']" @click="handleImport">导入</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" v-hasPermi="['archive:mgck:export']" @click="handleExport">导出</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download"
                           v-hasPermi="['archive:mgck:export']" @click="handleExportAll">全部导出</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-s-claim"  v-hasPermi="['archive:mgck:editall']" @click="handleTapArr(0)">启用</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="info" plain icon="el-icon-s-release"  v-hasPermi="['archive:mgck:editall']" @click="handleTapArr(1)">冻结</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" border :data="list" @selection-change="handleSelectionChange" :height="tableHeight">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" type="index" prop="dictId" align="center" />
            <el-table-column label="名称" prop="name" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="备注" prop="beizhu" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="状态" prop="state" align="center" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <p v-for="(item, index) in stateList" :key="index">{{ item.value == scope.row.state ? item.label : '' }}
                    </p>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">

                    <el-button type="text" icon="el-icon-edit"  @click="handleUpdate(scope.row)">修改</el-button>
                    <el-button  type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
                    <el-button type="text" plain icon="el-icon-s-claim"
                        @click="handleTap(scope.row, 0)">启用</el-button>
                    <el-button type="text" plain icon="el-icon-s-release"
                        @click="handleTap(scope.row, 1)">冻结</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
        <deitSensitive v-if="deitOpen" :open="deitOpen" :id="id" :stateList="stateList" @closeDelDialog="closeDelDialog1"
            @submitForm="submitFormTap"></deitSensitive>


        <vimport v-if="upload.open" :upload="upload" @closeDelDialog="closeDelDialog1" accept=".xlsx, .xls"
            @handleFileSuccess="handleFileSuccess"></vimport>

    </div>
</template>

<script>
import { mingancilist, mingancidelete, plxg } from "@/api/archive/archivalAppraisal/openness/sensitive"
import estimateTableHeight from '@/mixins/estimateTableHeight';
import deitSensitive from "@/views/archive/archivalAppraisal/openness/sensitive/deitSensitive.vue"
import vimport from '@/components/import/index.vue';
import { getToken } from "@/utils/auth";
//vue项目中element-tabel自动计算高度
export default {
    name: "senstitive",
    mixins: [estimateTableHeight], // 混入方法
    components: {
        deitSensitive,
        vimport
    },
    data() {
        return {
            // 遮罩层
            loading: true,
            id: "",//修改用
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            list: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                name: "",
                state: ""
            },
            detailsOpen: false,
            stateList: [
                {
                    label: "启用",
                    value: 0,
                }, {
                    label: "冻结",
                    value: 1,
                }
            ],
            deitOpen: false,

            // 用户导入参数
            upload: {
                // 是否显示弹出层（用户导入）
                open: false,
                // 弹出层标题（用户导入）
                title: "导入",
                // 是否禁用上传
                isUploading: false,
                deptId: null,
                // 是否更新已经存在的用户数据
                updateSupport: 0,
                // 设置上传的请求头部
                headers: { Authorization: "Bearer " + getToken() },
                // 上传的地址
                url: process.env.VUE_APP_BASE_API + "/archive/minganci/import",
                // 下载模板的地址
                urlTemplate: "/archive/minganci/importmodel"
            },
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询字典列表 */
        getList() {
            this.loading = true;
            console.log(this.queryParams)
            mingancilist(this.queryParams).then(response => {
                this.list = response.rows;
                this.total = response.total;
                this.loading = false;
            }
            );
        },
        // 表单重置
        reset() {
            this.queryParams = {
                pageNum: 1,
                pageSize: 10,
                name: "",
                state: "",
            };
        },
        /** 搜索按钮操作 */
        handleQuery() {

            this.getList();

        },
        /** 重置按钮操作 */
        resetQuery() {
            this.reset();
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length != 1
            this.multiple = !selection.length;
            this.label = selection.map(item => item.name)
        },


        //修改
        handleUpdate(row) {
            this.id = row.id;
            this.deitOpen = true;
        },
        //添加
        handleAdd() {

            this.deitOpen = true;
        },

        closeDelDialog1() {
            this.id = "";
            this.deitOpen = false;
            this.upload.open = false;
        },

        submitFormTap() {
            this.getList();
            this.id = "";
            this.deitOpen = false;
        },

        //单个删除
        handleDelete(row) {

            this.deleteDataPOST(row.id, row.name);

        },
        //多选删除
        handleDeleteAll(row) {
            const label = row.name || this.label
            if (!this.multiple) {
                this.deleteDataPOST(this.ids, label)
            } else {
                this.$message({ message: '请选择要删除的数据!', type: 'warning' })
            }

        },

        deleteDataPOST(ids, label) {
            this.$modal.confirm('是否确认删除"' + label + '"的数据项？').then(function () {
                return mingancidelete(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            if (!this.multiple) {
                this.download('/archive/isopenidentify/exportck', { ids: this.ids.toString() }, `export_${new Date().getTime()}.xlsx`)
            } else {
                this.$message({ message: '请选择要导出的数据!', type: 'warning' })
            }
        },
        /**导出全部操作 */
        handleExportAll() {
            this.download('/archive/isopenidentify/exportck', { ids: '' }, `export_${new Date().getTime()}.xlsx`)
        },
        // 导入按钮操作
        handleImport() {
            this.upload.open = true;
        },

        //导入结果返回操作
        handleFileSuccess(response) {
            this.upload.open = false;
            this.upload.isUploading = false;
            if (response.code == "500") {
                this.$message({ message: response.msg, type: 'error' })

            } else {
                this.getList();
            }


        },

        //启用和冻结 state integer 0:启用,1:冻结
        handleTapArr(state) {
            let text = state === 0 ? "启用" : "冻结";
            if (!this.multiple) {
                plxg({
                    ids: this.ids,
                    state: state
                }).then(res => {
                    this.$modal.msgSuccess(res.msg);
                    this.getList();
                })
            } else {
                this.$message({ message: '请选择要' + text + '的数据!', type: 'warning' })
            }
        },

        //单个启用和冻结
        handleTap(row, state) {
            plxg({
                ids: [row.id],
                state: state
            }).then(res => {
                this.$modal.msgSuccess(res.msg);
                this.getList();
            })
        },
        // 查看详情
        handleDetails(row) {
            this.detailInfo = row;
            this.detailsOpen = true;
        },

        //关闭详情
        closeDelDialog() {
            this.detailsOpen = false;
        }

    }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: calc(100% - 30px);
    max-width: calc(100% - 30px);
}

::v-deep .el-dialog .el-dialog__body {
    flex: 1;
    overflow: auto;
}

::v-deep .el-form-item__content {
    line-height: 26px;
}</style>
